package com.cqjtu.store.order.controller;

import com.cqjtu.store.common.JwtUtils;
import com.cqjtu.store.common.R;
import com.cqjtu.store.order.pojo.vo.OrderItemVO;
import com.cqjtu.store.order.pojo.vo.OrderVO;
import com.cqjtu.store.order.service.OrderService;
import com.cqjtu.store.user.pojo.vo.UserLoginVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @ProjectName: cqjtu-store
 * @Titile: OrderController
 * @Author: Lucky
 * @Description: 订单控制类
 */
@RestController
@RequestMapping("api/order")
@Slf4j
@Api(tags = "订单管理")
public class OrderController {
    @Autowired
    private OrderService orderService;
    /**
     * 获取订单列表
     * @param request
     * @return
     */
    @GetMapping("list/{status}")
    @ApiOperation("获取订单列表")
    public R<List<OrderVO>> getOrderList(@PathVariable("status") Integer status, HttpServletRequest request){
        String token = request.getHeader("Authorization");
        UserLoginVO userLoginVO = JwtUtils.parseToken(token);
        List<OrderVO> orderVOList =  orderService.getList(status,userLoginVO);
        return R.ok(orderVOList);
    }

    @PutMapping("setStatus/{id}/{status}")
    public R<Void> setStatus (@PathVariable("id") Integer id,@PathVariable("status")Integer status,HttpServletRequest request){
        //获取用户身份
        String token = request.getHeader("Authorization");
        UserLoginVO userLoginVO=JwtUtils.parseToken(token);
        orderService.setStatus(id,status,userLoginVO);
        return R.ok();
    }

}
